package com.narbeshuber.tablet.lasalara.listadapters;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.narbeshuber.tablet.lasalara.LasaLaraActivity;
import com.narbeshuber.tablet.lasalara.R;
import com.narbeshuber.tablet.lasalara.Utils;
import com.narbeshuber.tablet.lasalara.model.Question;

public class QuestionListAdapter extends BaseAdapter{
	
	private LasaLaraActivity context;
	private List<Question> questions;
	
	public QuestionListAdapter(LasaLaraActivity context, List<Question> questions) {
		super();
		this.context = context;
		this.questions = questions;
	}

	public int getCount() {
		return questions.size();
	}

	public Question getItem(int position) {
		return questions.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {

		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(com.narbeshuber.tablet.lasalara.R.layout.questionlistrow, null);
		}
		TextView question = (TextView)convertView.findViewById(com.narbeshuber.tablet.lasalara.R.id.question);
		TextView answer = (TextView)convertView.findViewById(com.narbeshuber.tablet.lasalara.R.id.answer);
		question.setTextSize(Utils.getTextSize());
		answer.setTextSize(Utils.getTextSize());
		if(!LasaLaraActivity.reverseMode){
			question.setText(getItem(position).getQuestion());
			answer.setText(getItem(position).getAnswer());
		} else {
			question.setText(getItem(position).getAnswer());
			answer.setText(getItem(position).getQuestion());
		}
		
		if(LasaLaraActivity.ninjaMode){
			question.setTextColor(Color.WHITE);
			answer.setTextColor(context.getResources().getColor(R.color.pageview_anwser));
		} else {
			question.setTextColor(Color.BLACK);
			answer.setTextColor(context.getResources().getColor(R.color.pageview_anwser));
		}
		
		answer.setVisibility(View.GONE);
		convertView.findViewById(R.id.anwserLine).setVisibility(View.GONE);
		return convertView;
	}
	
	

}
